<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<div>距离下一个元旦还有多久:</div>
		<div id="timer"></div>

		<script type="text/javascript">
			function nextTime() {
				var now = new Date();
				//距离下一个元旦还有多久
				var end = new Date(now.getFullYear() + 1, 0, 1);
				//两个时间差
				var time = end.getTime() - now.getTime();
				//转换成秒
				var sec = time / 1000;
				//转换成天
				var day = Math.floor(sec / 60 / 60 / 24);
				//转换成时
				var hour = sec / 60 / 60;
				//转换成分
				var min = sec / 60;

				var lhour = Math.floor(hour % 24);
				var lmin = Math.floor(min % 60);
				var lsec = Math.floor(sec % 60);

				document.getElementById("timer").innerHTML = day + "天" + lhour + "时" + lmin + "分" + lsec + "秒";

			}

			setInterval(nextTime, 1000);
		</script>
	</body>

</html>